package com.hhf.demo_06;

import java.util.Collections;
import java.util.List;

/**
 * @Author: 黄恒锋
 * @DateTime: 2024/5/12 16:49
 * @Description: TODO
 */
public class MyThread extends Thread{


    List<Integer> list;
    public MyThread(List<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {

        while (true){
            synchronized (MyThread.class){
                if(list.size() == 0){
                    break;
                }else {
                    // 打乱集合的元素顺序
                    Collections.shuffle(list);
                    // 删除的时候返回被删除的元素值
                    Integer num = list.remove(0);
                    System.out.println("又产生了一个大奖，奖金为"+num+"元");
                }
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
